package pl.bristleback.chat.utils;

import org.apache.log4j.Logger;
import org.jwebsocket.api.WebSocketConnector;
import org.jwebsocket.token.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import pl.bristleback.chat.constants.UserState;
import pl.bristleback.server.bristle.messages.RightsCheckingMessageBroadcaster;
import pl.bristleback.server.bristle.messages.SimpleConnectorMessageSender;

/**
 * //@todo class description
 * <p/>
 * Created on: 13.04.11 16:30 <br/>
 *
 * @author Paweł Machowski
 */
@Controller
public class SendMessageSupport {
  private static Logger log = Logger.getLogger(SendMessageSupport.class.getName());

  @Autowired
  private RightsCheckingMessageBroadcaster broadcaster;

  @Autowired
  private SimpleConnectorMessageSender sender;

  public void broadcast(Token token, String[] requiredRights){
    broadcaster.sendMessage(token, requiredRights);
  }


  public void broadcastLogged(Token token){
    broadcast(token, new String[]{ UserState.LOGGED.toString()}
);
  }
  public void send(Token token, WebSocketConnector connector){
    sender.sendMessage(token, connector);
  }

} 